#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#define LEN 1000
int main(void)
{
	char tmp[LEN+1];
	char result[LEN];
	int sour,dis;
	int size;
	int i,j;
	sour = open("source.js",O_RDONLY);
	if (sour < 0)
	{
		printf("open file  error \n");
		exit(1);
	}
	printf("%d\n",sour);
	dis = open("dist.js",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
	if (dis < 0 )
	{
		printf("Open file errors dis \n");
		exit(1);
	}
	size = 1000;
	i = 0;
	j = 0;
	memset(result,'\0',LEN);
	while (size > 0)
	{
		memset(tmp,'\0',LEN+1);
		size = read(sour,tmp,LEN);
		if (size < 0 ) 
		{
			printf("%s\n",strerror(errno));
			perror("read error");
		}
		while (i < size)
		{
			if ( i > 1 && i < size -1) 
			{
				if (tmp[i]==' ' &&tmp[i-1]>'z'&&tmp[i-1]<'A'&&tmp[i+1]>'z'&&tmp[i+1]<'A')
					i++;
				if (tmp[i]=='/'&&tmp[i+1]=='/')
					while(tmp[i] != '\n')
						i++;
				
			}
			result[j] = tmp[i];
			i++;
			j++;
			if ( j == LEN-1 )
			{
				write(dis,result,LEN-1);
				memset(result,'\0',LEN);
				j = 0;
			}
		}	
		
	}
	write(dis,result,j+1);
	close(sour);
	close(dis);
	return 0;	

}
